An R experiment to create images generated by the trajectory of a particle according to Clifford attractors.
Made with Rcpp, tidyverse
Blog post explaining the experiment: Drawing 10 Million Points With ggplot: Clifford Attractors
Inspired by: Clifford Attractors, by Paul Bourke
library(Rcpp)
library(tidyverse)
opt <- theme(legend.position = "none",
panel.background = element_rect(fill="white"),
plot.background = element_rect(fill="white"),
axis.ticks = element_blank(),
panel.grid = element_blank(),
axis.title = element_blank(),
axis.text = element_blank())
cppFunction('DataFrame createTrajectory(int n, double x0, double y0,
double a, double b, double c, double d) {
// create the columns
NumericVector x(n);
NumericVector y(n);
x[0]=x0;
y[0]=y0;
for(int i = 1; i < n; ++i) {
x[i] = sin(a*y[i-1])+c*cos(a*x[i-1]);
y[i] = sin(b*x[i-1])+d*cos(b*y[i-1]);
}
// return a new data frame
return DataFrame::create(_["x"]= x, _["y"]= y);
}
')
a <- -1.5355
b <- 1.4388
c <- 1.9679
d <- -1.6252
df <- createTrajectory(10000000, 0, 0, a, b, c, d)
plot <- ggplot(df, aes(x, y)) +
geom_point(color="black", shape=46, alpha=.01) +
opt
plot